<template>
  <div class="wh-100 " style="background-color: white">
    <div class="w-100  bor-base-b d-flex-between-center pl-12 pr-12 ch50">
      <div class="fw-6 fs-14" v-if="$route.query.enterpriseName">({{ $route.query.enterpriseName || '' }})用人单位就业统计</div>
      <div class="fw-6 fs-14" v-else>手机号预警名单统计</div>
      <div class="d-flex-align-center">
        <Button style="background-color: white" @click="goBack">返回</Button>
        <Button type="primary" @click="downloadAll">导出全部数据</Button>
      </div>
    </div>
    <div class="w-100 h-95 pt-12">
      <div class="w-100  h-5   d-flex-align-center">
        <Select v-if="userInfo.resource == 1" v-model="searchForm.schoolName" class="w-10 ml-8" clearable
                placeholder="所有高校">
          <Option v-for="item in schoolList" :key="item.code" :value="item.name">{{ item.name }}</Option>
        </Select>
        <Select v-if="userInfo.resource == 1 || userInfo.resource == 2" v-model="searchForm.collegeName"
                class="w-15 ml-8" clearable placeholder="所有院系">
          <Option v-for="item in collegeList" :key="item" :value="item">{{ item }}</Option>
        </Select>
        <Input v-model="searchForm.profession" class="w-10 ml-8" clearable placeholder="专业" />
        <el-select v-model="searchForm.graduationCode" class="w-15 ml-8" clearable placeholder="毕业去向" size="small">
          <el-option
              v-for="item in employmentCategoryList"
              :key="item.profCode"
              :label="item.title.substr(0, 20)"
              :value="item.profCode">
          </el-option>
        </el-select>
        <Input v-model="searchForm.studentCard" class="w-10 ml-8" clearable placeholder="学号" />
        <Input v-model="searchForm.studentName" class="w-10 ml-8" clearable placeholder="姓名" />
        <Select v-if="userInfo.resource == 3" v-model="searchForm.schoolAudit" class="w-10 ml-8" clearable
                placeholder="是否核查">
          <Option value="0">未核查</Option>
          <Option value="1">已核查</Option>
        </Select>
        <Select v-if="userInfo.resource == 1 || userInfo.resource == 2" v-model="searchForm.schoolAudit"
                class="w-10 ml-8" clearable placeholder="学校核查">
          <Option value="0">未核查</Option>
          <Option value="1">已核查</Option>
        </Select>
        <Select v-if="userInfo.resource == 1 " v-model="searchForm.provinceAudit"
                class="w-10 ml-8" clearable placeholder="省级核查">
          <Option value="0">未核查</Option>
          <Option value="1">已核查</Option>
        </Select>
      </div>
      <div class="w-100  h-5   d-flex-align-center">
        <Select v-model="searchForm.materialAudit" class="w-15 ml-8" clearable placeholder="材料核查">
          <Option v-for="item in materialVerification" :key="item.value" :value="item.value">{{ item.title }}</Option>
        </Select>
        <Select v-model="searchForm.studentAudit" class="w-15 ml-8" clearable placeholder="学生电话核查">
          <Option v-for="item in studentPhoneCheck" :key="item.value" :value="item.value">{{ item.title }}</Option>
        </Select>
        <Select v-model="searchForm.enterpriseAudit" class="w-15 ml-8" clearable placeholder="用人单位电话核查">
          <Option v-for="item in employerTelephoneVerification" :key="item.value" :value="item.value">{{ item.title }}
          </Option>
        </Select>
        <Button type="primary" @click="searchSelect">查询</Button>
        <Button @click="downloadSearch">下载当前查询数据</Button>
      </div>
      <div v-loading="tableLoading" v-ref-height="refHeight" class="w-100 h-80 mt-8  ">
        <Table
            ref="table"
            :columns="tableColumns"
            :data="tableData"
            :height="refHeight.value"
            border
            no-data-text="暂无数据"
        >
          <template slot="action" slot-scope="{ row, index }">
            <Button v-if="userInfo.resource ==1 || userInfo.resource == 2" type="primary" @click="startChecking(row)">
              开始核查
            </Button>
            <Button v-if="userInfo.resource ==3" type="primary" @click="selectCheck(row)">查看</Button>

          </template>
        </Table>
      </div>
      <div class="w-100 h-5  d-flex-align-center mt-16">
        <Page
            :current="pages.pageNumber"
            :page-size="pages.pageSize"
            :total="pages.total"
            class-name="d-flex-center"
            show-elevator
            show-sizer
            show-total
            size="small"
            @on-change="changePage"
            @on-page-size-change="changePageSize"
        />
      </div>
    </div>
  </div>
</template>

<script>
import { getAllCollege, proGetAllCollage } from '../../api/bys/yx/yx';

import { accessToAllNonProvincialSchoolsApi } from '../../api/bys/gxjyl/jyqx';
import {
  exportAllData,
  exportConditionData,
  getEnterprisePageDataAuditDataApi
} from '../../api/dataVerification/dataVerification';
import { employmentCategoryAPI } from '../../api/bys';
import { employerTelephoneVerification, materialVerification, studentPhoneCheck } from './enums';
import { getDictDataByType } from '@/api';

export default {
  data() {
    return {
      tableLoading: false,
      downloadSearchLoading: false,
      downloadLoading: false,
      refHeight: { value: 0 },
      columnsOne: [],
      // columnsOne_1
      columnsOne_1: [
        {
          title: '专业',
          minWidth: 200,
          key: 'profession'
        },
        {
          title: '学号',
          minWidth: 200,
          key: 'studentCard'
        },
        {
          title: '姓名',
          minWidth: 200,
          key: 'studentName'
        },
        {
          title: '单位名称',
          minWidth: 200,
          key: 'enterpriseName'
        },
        {
          title: '毕业去向',
          minWidth: 150,
          key: 'oneType',
          render: (h, params) => {
            let item = this.qxList.find(item => item.value === params.row.oneType);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '去向分类',
          minWidth: 200,
          key: 'qxName'
        },
        {
          title: '联系方式',
          minWidth: 200,
          key: 'studentMobile'
        },
        {
          title: '单位联系人',
          minWidth: 200,
          key: 'enterpriseContact'
        },
        {
          title: '单位联系方式',
          minWidth: 200,
          key: 'enterpriseMobile'
        },
        {
          title: '材料核查',
          minWidth: 300,
          key: 'materialAudit',
          render: (h, params) => {
            let item = this.materialVerification.find(item => item.value == params.row.materialAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '材料核查说明',
          minWidth: 300,
          key: 'materialAuditMessage'
        },
        {
          title: '学生电话核查',
          width: 300,
          key: 'studentAudit',
          render: (h, params) => {
            let item = this.studentPhoneCheck.find(item => item.value == params.row.studentAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '学生电话核查说明',
          width: 300,
          key: 'studentAuditMessage'
        },
        {
          title: '用人单位电话核查',
          width: 300,
          key: 'enterpriseAudit',
          render: (h, params) => {
            let item = this.employerTelephoneVerification.find(item => item.value == params.row.enterpriseAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '用人单位电话核查说明',
          width: 300,
          key: 'enterpriseAuditMessage'
        },
        {
          title: '其他核查情况',
          width: 120,
          key: 'otherAudit'
        },
        {
          title: '核查时间',
          minWidth: 200,
          key: 'auditTime'
        },
        {
          title: '学校是否核查',
          key: 'schoolAudit',
          align: 'center',
          width: 120,
          fixed: 'right',
          render: (h, params) => {
            return h('div', params.row.schoolAudit == 1 ? '已核查' : '未核查');
          }
        },
        {
          title: '省级是否核查',
          key: 'provinceAudit',
          align: 'center',
          width: 120,
          fixed: 'right',
          render: (h, params) => {
            return h('div', params.row.provinceAudit == 1 ? '已核查' : '未核查');
          }
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          width: 120,
          fixed: 'right'
        }
      ],
      columnsTwo: [],
      columnsTwo_1: [
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '专业',
          minWidth: 200,
          key: 'profession'
        },
        {
          title: '学号',
          minWidth: 200,
          key: 'studentCard'
        },
        {
          title: '姓名',
          minWidth: 200,
          key: 'studentName'
        },
        {
          title: '单位名称',
          minWidth: 200,
          key: 'enterpriseName'
        },
        {
          title: '毕业去向',
          minWidth: 150,
          key: 'oneType',
          render: (h, params) => {
            let item = this.qxList.find(item => item.value === params.row.oneType);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '去向分类',
          minWidth: 200,
          key: 'qxName'
        },
        {
          title: '联系方式',
          minWidth: 200,
          key: 'studentMobile'
        },
        {
          title: '单位联系人',
          minWidth: 200,
          key: 'enterpriseContact'
        },
        {
          title: '单位联系方式',
          minWidth: 200,
          key: 'enterpriseMobile'
        },
        {
          title: '材料核查',
          minWidth: 300,
          key: 'materialAudit',
          render: (h, params) => {
            let item = this.materialVerification.find(item => item.value == params.row.materialAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '材料核查说明',
          minWidth: 200,
          key: 'materialAuditMessage'
        },
        {
          title: '学生电话核查',
          width: 300,
          key: 'studentAudit',
          render: (h, params) => {
            let item = this.studentPhoneCheck.find(item => item.value == params.row.studentAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '学生电话核查说明',
          width: 120,
          key: 'studentAuditMessage'
        },
        {
          title: '用人单位电话核查',
          width: 300,
          key: 'enterpriseAudit',
          render: (h, params) => {
            let item = this.employerTelephoneVerification.find(item => item.value == params.row.enterpriseAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '用人单位电话核查说明',
          width: 120,
          key: 'enterpriseAuditMessage'
        },
        {
          title: '其他核查情况',
          width: 120,
          key: 'otherAudit'
        },
        {
          title: '核查时间',
          minWidth: 200,
          key: 'auditTime'
        },
        {
          title: '是否核查',
          key: 'schoolAudit',
          align: 'center',
          width: 120,
          fixed: 'right',
          render: (h, params) => {
            return h('div', params.row.schoolAudit == 1 ? '已核查' : '未核查');
          }
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          width: 120,
          fixed: 'right'
        }
      ],
      tableColumns: [],
      tableColumns_1: [
        {
          type: 'index',
          width: 60,
          align: 'center'
        },
        {
          title: '专业',
          minWidth: 200,
          key: 'profession'
        },
        {
          title: '学号',
          minWidth: 200,
          key: 'studentCard'
        },
        {
          title: '姓名',
          minWidth: 200,
          key: 'studentName'
        },
        {
          title: '单位名称',
          minWidth: 200,
          key: 'enterpriseName'
        },
        {
          title: '毕业去向',
          minWidth: 150,
          key: 'oneType',
          render: (h, params) => {
            let item = this.qxList.find(item => item.value === params.row.oneType);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '去向分类',
          minWidth: 200,
          key: 'qxName'
        },
        {
          title: '联系方式',
          minWidth: 200,
          key: 'studentMobile'
        },
        {
          title: '单位联系人',
          minWidth: 200,
          key: 'enterpriseContact'
        },
        {
          title: '单位联系方式',
          minWidth: 200,
          key: 'enterpriseMobile'
        },
        {
          title: '材料核查',
          minWidth: 300,
          key: 'materialAudit',
          render: (h, params) => {
            let item = this.materialVerification.find(item => item.value == params.row.materialAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '材料核查说明',
          minWidth: 200,
          key: 'materialAuditMessage'
        },
        {
          title: '学生电话核查',
          width: 300,
          key: 'studentAudit',
          render: (h, params) => {
            let item = this.studentPhoneCheck.find(item => item.value == params.row.studentAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '学生电话核查说明',
          width: 120,
          key: 'studentAuditMessage'
        },
        {
          title: '用人单位电话核查',
          width: 300,
          key: 'enterpriseAudit',
          render: (h, params) => {
            let item = this.employerTelephoneVerification.find(item => item.value == params.row.enterpriseAudit);
            return h('div', item ? item.title : '');
          }
        },
        {
          title: '用人单位电话核查说明',
          width: 120,
          key: 'enterpriseAuditMessage'
        },
        {
          title: '其他核查情况',
          width: 120,
          key: 'otherAudit'
        },
        {
          title: '核查时间',
          minWidth: 200,
          key: 'auditTime'
        },
        {
          title: '学校是否核查',
          key: 'schoolAudit',
          align: 'center',
          width: 120,
          fixed: 'right',
          render: (h, params) => {
            return h('div', params.row.schoolAudit == 1 ? '已核查' : '未核查');
          }
        },
        {
          title: '省级是否核查',
          key: 'provinceAudit',
          align: 'center',
          width: 120,
          fixed: 'right',
          render: (h, params) => {
            return h('div', params.row.provinceAudit == 1 ? '已核查' : '未核查');
          }
        },
        {
          title: '操作',
          slot: 'action',
          align: 'center',
          width: 120,
          fixed: 'right'
        }
      ],
      tableData: [],
      qxList: [],
      pages: {
        pageSize: 10,
        pageNumber: 1,
        total: 0
      },
      schoolList: [],
      collegeList: [],
      materialVerification,
      studentPhoneCheck,
      employerTelephoneVerification,
      employmentCategoryList: [],
      searchForm: {
        enterpriseCode: '',
        enterpriseName: '',
        graduationCode: '',
        dwdh:''
      },
      userInfo: JSON.parse(Cookies.get('userInfo')),
      active:0

    };
  },
  methods: {
    downloadAll() {
      this.downloadLoading = true;
      exportAllData({
        enterpriseName: this.searchForm.enterpriseName,
        enterpriseCode: this.searchForm.enterpriseCode
      }).then(res => {
        // type的格式可以可以设置，可以把appcation/json设置进去，然后设置导出的类型
        const blob = new Blob([res], { type: 'charset=utf-8' });
        let url = window.URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', '数据核查.xlsx');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link); // 删除节点
        window.URL.revokeObjectURL(url); //释放该 url
        this.downloadLoading = false;
      });
    },
    downloadSearch() {
      this.downloadSearchLoading = true;
      exportConditionData(this.searchForm).then(res => {
        // type的格式可以可以设置，可以把appcation/json设置进去，然后设置导出的类型
        const blob = new Blob([res], { type: 'charset=utf-8' });
        let url = window.URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', '当前查询数据核查.xlsx');
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link); // 删除节点
        window.URL.revokeObjectURL(url); //释放该 url
        this.downloadSearchLoading = false;
      });
    },
    employmentCategoryData() {
      employmentCategoryAPI().then(res => {
        this.employmentCategoryList = res.result;
        console.log('employmentCategoryList', this.employmentCategoryList);
      });
      getDictDataByType('qx').then(res => {
        if (res.success) {
          this.qxList = res.result;
        }
      });
    },
    goBack(){
      this.$router.push({
        path:'/dataWarning',
        query:{
          type:this.active||0
        }
      })
    },
    searchSelect() {
      this.pages.pageNumber = 1;
      this.getEnterprisePage();
    },
    getEnterprisePage() {
      this.tableLoading = true;
      getEnterprisePageDataAuditDataApi({ ...this.searchForm, ...this.pages }).then(res => {
        this.tableData = res.result.records;
        this.pages.total = res.result.total || 0;
        this.tableLoading = false;
        console.log('getEnterprisePageDataAuditDataApi.', res);
      });
    },
    getSchoolList() {
      // 学校
      accessToAllNonProvincialSchoolsApi().then(res => {
        if (res.success) {
          this.schoolList = res.result;
          let arr = {
            code: 0,
            name: '所有学校'
          };
          this.schoolList.unshift(arr);
          // if (res.result.length > 0) {
          //     this.searchForm.gx = res.result[0].code;
          // }
          console.log('所有学校', res.result);
        }
      });
    },
    getCollegeList() {
      let userInfo = JSON.parse(Cookies.get('userInfo'));
      if (userInfo.resource == 1) {
        proGetAllCollage().then(res => {
          if (res.success) {
            if (res.result.length > 0) {
              this.collegeList = res.result;
            }
            this.showCollapse = true;
          }
        });
      } else if (userInfo.resource == 2) {
        this.showCollapse = true;
        getAllCollege({ gxcode: userInfo.gxcode }).then(res => {
          if (res.success) {
            if (res.result.length > 0) {
              res.result.map(item => {
                this.collegeList.push(item.yxname);
              });
            }
            this.showCollapse = true;
          }
        });
      }

    },
    selectCheck(row) {
      this.$router.push({ name: 'CheckDetails',  query: { type: '0',id:row.id, idCard:row.idCard} });

    },
    // 开始核查
    startChecking(row) {
      this.$router.push({ name: 'CheckDetails', query: { type: '1',id:row.id, idCard: row.idCard } });
    },
    changePage: function(val) {
      this.pages.pageNumber = val;
      this.getEnterprisePage();
    },
    changePageSize: function(val) {
      this.pages.pageSize = val;
      this.getEnterprisePage();
    },
    onRestWindow() {
      this.tableColumns = this.restTableCellWidth(this.tableColumns_1);
      this.columnsOne = this.restTableCellWidth(this.columnsOne_1);
      this.columnsTwo = this.restTableCellWidth(this.columnsTwo_1);
      // this.labelWidth = this.searchLabelWidth(this.labelWidth)
    }
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.onRestWindow);
  },
  mounted() {
    this.onRestWindow();
    window.addEventListener('resize', this.onRestWindow);
    let userInfo = JSON.parse(Cookies.get('userInfo'));
    let columnsIndex = -1, that = this;
    if (userInfo.resource == 1) {
      let arr = [
        {
          title: '学校',
          minWidth: 200,
          key: 'schoolName'
        },
        {
          title: '院系',
          minWidth: 200,
          key: 'college'
        }
      ];
      let arr01 = this.restTableCellWidth(arr);
      this.columnsOne.map((list,index)=>{
        if (list.title == "其他核查情况") {
          list.title = '其他核查情况(省级)';
          let row  = {
            title: '其他核查情况(学校)',
            minWidth:120,
            key: 'otherAuditSchool',
          };
          that.columnsOne.splice(index+1, 0, row);
        }
        if (list.title == "核查时间") {
          list.title = '核查时间(省级)';
          let row  = {
            title: '核查时间(学校)',
            minWidth: 200,
            key: 'auditTimeSchool',
          };
          that.columnsOne.splice(index+1, 0, row);
        }
      })
      this.tableColumns = arr01.concat(this.columnsOne);
      this.tableColumns.map((list, index) => {
        if (list.title == "材料核查") {
          list.title = '材料核查(省级)';
          // that.tableColumns.splice(index, 0, row);
        }
        if (list.title == "材料核查说明") {
          list.title = '材料核查说明(省级)';
          let row1 = {
            title: '材料核查说明(学校)',
            minWidth: 200,
            key: 'materialAuditMessageSchool'
          };
          let row = {
            title: '材料核查(学校)',
            minWidth: 300,
            key: 'materialAuditSchool',
            render: (h, params) => {
              let item = this.materialVerification.find(item => item.value == params.row.materialAuditSchool);
              return h('div', item ? item.title : '');
            }
          };
          that.tableColumns.splice(index+1, 0, row1);
          that.tableColumns.splice(index+1, 0, row);
        }
        if (list.title == "学生电话核查") {
          list.title = '学生电话核查(省级)';

        }
        if (list.title == "学生电话核查说明") {
          list.title = '学生电话核查说明(省级)';
          let row1 = {
            title: '学生电话核查说明(学校)',
            minWidth: 300,
            key: 'studentAuditMessageSchool',
          };
          let row  = {
            title: '学生电话核查(学校)',
            minWidth: 300,
            key: 'studentAuditSchool',
            render: (h, params) => {
              let item = this.studentPhoneCheck.find(item => item.value == params.row.studentAuditSchool);
              return h('div', item ? item.title : '');
            }
          };
          that.tableColumns.splice(index+1, 0, row1);
          that.tableColumns.splice(index+1, 0, row);

        }
        if (list.title == "用人单位电话核查") {
          list.title = '用人单位电话核查(省级)';

        }
        if (list.title == "用人单位电话核查说明") {
          list.title = '用人单位电话核查说明(省级)';
          let row1 = {
            title: '用人单位电话核查说明(学校)',
            minWidth: 300,
            key: 'enterpriseAuditMessageSchool',
          };
          let row  = {
            title: '用人单位电话核查(学校)',
            minWidth: 300,
            key: 'enterpriseAuditSchool',
            render: (h, params) => {
              let item = this.employerTelephoneVerification.find(item => item.value == params.row.enterpriseAuditSchool);
              return h('div', item ? item.title : '');
            }
          };
          that.tableColumns.splice(index+1, 0, row1);
          that.tableColumns.splice(index+1, 0, row);

        }

      });
    }
    if (userInfo.resource == 2) {
      let arr = [
        {
          title: '院系',
          minWidth: 200,
          key: 'college'
        }
      ];
      let arr01 = this.restTableCellWidth(arr);
      this.tableColumns = arr01.concat(this.columnsOne);
      this.tableColumns.map((item, i) => {
        if (item.title == '省级是否核查') {
          columnsIndex = i;
        }
      });

      this.tableColumns.splice(columnsIndex, 1);
    }
    if (userInfo.resource == 3) {
      this.tableColumns = this.columnsTwo;
    }
    if (this.$route.query.enterpriseCode) {
      this.searchForm.enterpriseCode = this.$route.query.enterpriseCode;
    }
    this.active =this.$route.query.index|| 0;
    if (this.$route.query.enterpriseName) {
      this.searchForm.enterpriseName = this.$route.query.enterpriseName;
    }
    if( this.$route.query.dwdh){
      this.searchForm.dwdh= this.$route.query.dwdh
    }
    this.tableColumns.unshift({
      type: 'index',
      width: 60,
      title: '序号',
      align: 'center'
    });
    this.getCollegeList();
    this.getSchoolList();
    this.employmentCategoryData();
    this.getEnterprisePage();
  }
};
</script>

<style lang="less" scoped>
.ch50 {
  height: 50px;
}

// /deep/ .ivu-table .ivu-table-fixed-right .ivu-table-fixed-body {
//     height: 90% !important;
// }

@media (max-width: 1920px) {
  /deep/ .ivu-table .ivu-table-fixed-right {
    height: 98% !important;

  }

  /deep/ .ivu-table .ivu-table-fixed-body {
    height: 91% !important;
    overflow-y: auto;
  }
}

@media (min-width: 1921px) and (max-width: 3440px) {
  /deep/ .ivu-table .ivu-table-fixed-right {
    height: 98% !important;
  }

  /deep/ .ivu-table .ivu-table-fixed-body {
    height: 88.5% !important;
    overflow-y: auto;
  }

}
</style>